#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2021-present pkegg

. /etc/profile
DIR=$(realpath $(dirname $0))
BAND=$(get_ee_setting updates.type)
ORG=$(get_ee_setting updates.github.org)
if [ "$ORG" == "" ]; then
  ORG=AmberELEC
fi

REPO=$(get_ee_setting updates.github.repo)
if [ "$REPO" == "" ]; then
  if [ "$BAND" == "prerelease" ] || [ "$BAND" == "beta" ]; then
    REPO=AmberELEC-prerelease
  else
    REPO=AmberELEC
  fi
fi

FORCE=$(get_ee_setting updates.force)
if [ "$FORCE" == "1" ]; then
  FORCE_ARGS="--force-update"
fi

if UPDATE=$(python3 ${DIR}/get-release.py --org ${ORG} --band ${BAND} --repo ${REPO} ${FORCE_ARGS} --check True 2>/tmp/logs/update-check.log); then
   echo "${UPDATE}"
else
   echo "no"
   exit 1
fi 